//
//  AppDelegate.m
//  KingReaderSDKDemo
//
//  Created by wangbc on 16/3/31.
//  Copyright © 2016年 Shanghai Lianyou Network Technology Co., Ltd. All rights reserved.
//

#import "AppDelegate.h"
#import "KingReaderSDK.h"

/**
 关于 ThirdLoginSDK
 ThirdLoginSDK是开卷有益综合分享的一个SDK，git地址如下：
 https://git.oschina.net/comicisland/ThirdLoginSDK
 */
#import "ThirdLoginSDK.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

#pragma mark - ==========  横竖屏处理（此代码必须加上！！！）  ==========
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAll;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //注册通知
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge) categories:nil];
    [application registerUserNotificationSettings: settings];
    [application registerForRemoteNotifications];
    
    //添加分享
    NSString *weiboKey, *weiboSecret, *weiboUrl;
    [ThirdLoginSDK SSDKSetupSinaWeiboByAppKey:weiboKey appSecret:weiboSecret redirectUri:weiboUrl];
    NSString *wechatKey, *wechatSecret;
    [ThirdLoginSDK SSDKSetupWeChatByAppId:wechatKey appSecret:wechatSecret];
    NSString *qqAppid, *qqUrl;
    [ThirdLoginSDK SSDKSetupQQByAppId:qqAppid redirectUri:qqUrl];
    return YES;
}

#pragma mark - handle open url
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    [ThirdLoginSDK handleOpenURL:url];
    return NO;
}

#pragma mark - ==========  小米推送服务  ==========
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [KingReaderSDK bindDeviceTokenForMiPush:deviceToken];
    
    //辅助测试代码，为了方便console中查看
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSString *regid = [KingReaderSDK miPushRegID];
        NSLog(@"%@", regid);
    });
}


- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //自行处理注册远程推送失败.
    NSLog(@"失败 ");
}



@end
